/*
 *    Copyright 2011 The gcal-to-refill project
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.googlecode.gcal2refill;

import com.google.gdata.data.extensions.When;
import com.itextpdf.text.BaseColor;

import java.util.Calendar;
import java.util.Date;

public class Event {

	public Event(BaseColor color, String title, When when) {
		calenderColor = color;
		eventTitle = title;
		this.when = when;
	}

	public BaseColor getCalenderColor() {
		return calenderColor;
	}

	public String getEventTitle() {
		return eventTitle;
	}

	public When getWhen() {
		return when;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("\ncalenderColor : ");
		sb.append(calenderColor.getRGB());
		sb.append("\neventTitle : ");
		sb.append(eventTitle);
		sb.append("\nwhen.start : ");
		sb.append(when.getStartTime());
		sb.append("\nwhen.end : ");
		sb.append(when.getEndTime());
		return sb.toString();
	}

	public boolean isDateOnly() {
		return when.getStartTime().isDateOnly();
	}

	public String getWhenTimeString() {
		Calendar cal = Calendar.getInstance();
		StringBuffer sb = new StringBuffer();
		cal.setTime(new Date(when.getStartTime().getValue()));
		sb.append(cal.get(Calendar.HOUR_OF_DAY));
		sb.append(":");
		sb.append(addZeroMinute(cal.get(Calendar.MINUTE)));
		sb.append("-");
		cal.setTime(new Date(when.getEndTime().getValue()));
		sb.append(cal.get(Calendar.HOUR_OF_DAY));
		sb.append(":");
		sb.append(addZeroMinute(cal.get(Calendar.MINUTE)));
		sb.append(" ");
		return sb.toString();
	}

	private String addZeroMinute(int minute) {
		if (minute < 10)
			return (new StringBuilder("0")).append(minute).toString();
		else
			return String.valueOf(minute);
	}

	private BaseColor calenderColor;
	private String eventTitle;
	private When when;
}
